import axios from "axios"
import router from "@/router"
import { getCookiesAuthStr } from "@/utils/cache";
import API_HOST from "./host"
// 新建一个 axios 实例
const instance = axios.create({
	baseURL: API_HOST,
	withCredentials: true,
	timeout: 1000 * 12,
	headers: {
	}
})

// 添加请求拦截器
instance.interceptors.request.use(
	config => {
		// const token = getCookiesAuthStr()
		// if (token) {
		// 	config.headers['token'] = token
		// }
		return config
	},
	error => Promise.reject(error)
)

// 添加响应拦截器
instance.interceptors.response.use(
	// 响应成功
	res => {
		if (res.status === 200) {
				return Promise.resolve(res.data)
		} else {
			return Promise.reject(res)
		}
	},
	error => {
		const { response } = error
	}
)

export default instance
